#include <vector>
#include <string>
#include <sstream>
#include <iostream>
using namespace std;

class Solution 
{
public:
	vector<string> fullJustify(vector<string> &words, int L) 
	{
		// Start typing your C/C++ solution below
		// DO NOT write int main() function
		vector<string> result;
		if(words.empty()) 
			return result;

		size_t startIdx = 0;
		string tmp(L,' ');
		while(startIdx<words.size())
		{
			int totalLen = words[startIdx].size();
			size_t	curIdx = startIdx+1;
			while(curIdx<words.size() && totalLen<=L)
			{
				totalLen += words[curIdx].size()+1;				
				curIdx++;
			}

			tmp.replace(0,L,L,' ');
			if(curIdx<words.size() || totalLen>L)
			{
				curIdx--;
				totalLen -= (words[curIdx].size()+1);

				int left = L-totalLen;
				int nslot = curIdx-startIdx-1;

				tmp.replace(0,words[startIdx].size(),words[startIdx]);
				if(nslot!=0)
				{
					int ave = left/nslot;
					int npp = left%nslot;
					size_t cur = words[startIdx].size();
					for(int i=1;i<=npp;i++)
					{
						tmp.replace(cur+ave+2,words[startIdx+i].size(),words[startIdx+i]);
						cur += (ave+2+words[startIdx+i].size());
					}
					for(int i=npp+1;i<=nslot;i++)
					{
						tmp.replace(cur+ave+1,words[startIdx+i].size(),words[startIdx+i]);
						cur += (ave+1+words[startIdx+i].size());
					}				
				}
			}
			else
			{
				tmp.replace(0,words[startIdx].size(),words[startIdx]);
				size_t cur = words[startIdx].size();
				for(size_t x = startIdx+1;x<curIdx;cur+=(1+words[x++].size()))
					tmp.replace(cur+1,words[x].size(),words[x]);
			}


			result.push_back(tmp);
			startIdx = curIdx;
		}

		return result;
	}
};

int main()
{
	int n,l;
	Solution s;
	while(cin>>n)
	{
		if(n<=0)
			break;

		cin>>l;
		while(cin.get() != '\n');
		vector<string> words;
		string line;
		for(int i=0;i<n;i++)
		{
			getline(cin,line);
			words.push_back(line);
		}

		vector<string> lines = s.fullJustify(words,l);
		for(size_t i=0;i<lines.size();i++)
			cout<<lines[i]<<endl;
	}
}